package com.livideo.baseutilslibrary.utils;

import android.content.Context;
import android.os.Build;
import android.view.Window;


import com.livideo.baseutilslibrary.base.BaseApplication;

import java.lang.reflect.Method;
import java.util.Locale;

public class DeviceRom {
    private static int sEmuiLevel = -1;
    private static boolean sIsMiui;
    private static boolean sIsMiuiInited;
    private static String sMiuiVersion;
    private static int sStatusBarHeight = 0;

    static {
        sIsMiui = false;
        sIsMiuiInited = false;
    }

    public static boolean isFlyme() {
        return Build.DISPLAY.startsWith("Flyme");
    }

    public static boolean isFlyme2() {
        return Build.DISPLAY.startsWith("Flyme 2");
    }

    public static boolean isFlyme4() {
        return Build.DISPLAY.startsWith("Flyme OS 4");
    }

    public static boolean isHtcOs() {
        return (Build.BRAND != null) && (Build.BRAND.toLowerCase().contains("htc")) && (Build.MANUFACTURER != null) && (Build.MANUFACTURER.toLowerCase().contains("htc")) && (Build.MODEL != null) && (Build.MODEL.toLowerCase().contains("htc"));
    }

    public static boolean isHuawei() {
        return (Build.MANUFACTURER != null) && (Build.MANUFACTURER.toUpperCase().contains("HUAWEI"));
    }

    public static boolean isOPPO() {
        return (Build.MANUFACTURER != null) && (Build.MANUFACTURER.toUpperCase().contains("OPPO"));
    }

    public static boolean isVIVO() {
        return (Build.MANUFACTURER != null) && (Build.MANUFACTURER.toUpperCase().contains("VIVO"));
    }

    public static boolean isLG() {
        return (("lge".equalsIgnoreCase(Build.BRAND)) || ("lge".equalsIgnoreCase(Build.MANUFACTURER))) && (Build.MODEL != null) && (Build.MODEL.toLowerCase().contains("lg"));
    }

    public static boolean isLenovo() {
        return ("lenovo".equalsIgnoreCase(Build.BRAND)) || ("lenovo".equalsIgnoreCase(Build.MANUFACTURER));
    }

    public static boolean isMeizu() {
        String str = Build.BRAND;
        if (str == null) {
        }
        while (str.toLowerCase(Locale.ENGLISH).indexOf("meizu") <= -1) {
            return false;
        }
        return true;
    }

    public static boolean isMeizuMx3() {
        if (isMeizu()) {
            return "mx3".equalsIgnoreCase(Build.DEVICE);
        }
        return false;
    }

    public static boolean isMiui() {
        if (!sIsMiuiInited) {
        }
        try {
            if (Class.forName("miui.os.Build") != null) {
                sIsMiui = true;
            }
            sIsMiuiInited = true;
            return sIsMiui;
        } catch (Exception localException) {
            for (; ; ) {
            }
        }
    }

    public static boolean isOnePlusLOLLIPOP() {
        return (Build.BRAND.equals("ONEPLUS")) && (Build.VERSION.SDK_INT >= 21);
    }

    public static boolean isSamsung() {
        return ("samsung".equalsIgnoreCase(Build.BRAND)) || ("samsung".equalsIgnoreCase(Build.MANUFACTURER));
    }

    public static boolean isSumsungCorePrime() {
        return (isSamsung()) && (Build.DISPLAY.contains("G3608ZMU1AOA4"));
    }

    public static boolean isSumsungV4_4_4() {
        if (isSamsung()) {
            if (Build.VERSION.RELEASE.startsWith("4.4.4")) {
            }
            while ((Build.VERSION.RELEASE.startsWith("4.4.2")) && (Build.DEVICE.startsWith("klte"))) {
                return true;
            }
        }
        return false;
    }

    public static boolean isSumsungV5() {
        return (isSamsung()) && (Build.VERSION.SDK_INT >= 21);
    }

    public static void setMiuiStatusBarDarkMode(boolean paramBoolean, Window paramWindow) {
        int i = 0;
        try {
            Object localObject = paramWindow.getClass();
            Class localClass = Class.forName("android.view.MiuiWindowManager$LayoutParams");
            int j = localClass.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE").getInt(localClass);
            localObject = ((Class) localObject).getMethod("setExtraFlags", new Class[]{Integer.TYPE, Integer.TYPE});
            if (paramBoolean) {
                i = j;
            }
            ((Method) localObject).invoke(paramWindow, new Object[]{Integer.valueOf(i), Integer.valueOf(j)});
            return;
        } catch (Throwable a) {
            a.printStackTrace();
        }
    }

    /**
     * vivo是否刘海屏
     * 参数说明: 0x00000020 表示是否有凹槽; 0x00000008 表示是否有圆角
     *
     * @return
     */
    public static boolean isVivoFringe() {
        try {
            Class mClass = Class.forName("android.util.FtFeature");
            if (mClass == null) {
                return false;
            }
            Method method = mClass.getMethod("isFeatureSupport", int.class);
            boolean isFringe = (Boolean) method.invoke(null, 0x00000020);
            return isFringe;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * oppo是否刘海屏
     * 参数说明: 0x00000020 表示是否有凹槽; 0x00000008 表示是否有圆角
     *
     * @return
     */
    public static boolean isOppoFringe(Context context) {
        return context.getPackageManager().hasSystemFeature("com.oppo.feature.screen.heteromorphism");
    }

    public static boolean isHuaWeiFringe(Context context) {
        boolean ret = false;
        try {
            ClassLoader cl = context.getClassLoader();
            Class HwNotchSizeUtil = cl.loadClass("com.huawei.android.util.HwNotchSizeUtil");
            Method get = HwNotchSizeUtil.getMethod("hasNotchInScreen");
            ret = (boolean) get.invoke(HwNotchSizeUtil);
        } catch (ClassNotFoundException e) {
        } catch (NoSuchMethodException e) {
        } catch (Exception e) {
        } finally {
            return ret;
        }
    }

    public static boolean isXiaomiFringe() {
        try {
            Class<?> clz = Class.forName("android.os.SystemProperties");
            Method m = clz.getDeclaredMethod("get", String.class);
            String v = (String) m.invoke(clz.newInstance(), "ro.miui.notch");
            return "1".equals(v);
        } catch (Exception e) {
        }
        return false;
    }
}